package sequences;

/**
 * A sequence generator that produces "steps" of characters of a given size.
 * 
 * @author John Schaeffer
 *
 */
public class StepSequence implements CharSequence {

    private int stepSize;
    private int time;
    private char offset;
    
    /**
     * Constructs a StepSequence with the given step size.
     * 
     * @param stepSize The step size of the sequence.
     */
    public StepSequence(int stepSize) {
        this.stepSize = stepSize;
        this.time = 0;
        this.offset = 0;
    }
    
    /**
     * Produces the next character in the sequence, either on the current step,
     * next step, or wrapping around to 0.
     */
    public char nextChar() {
        
        // Wrap around if we're done!
        if(offset >= 25) {
            offset = 0;
        }
        
        // Or just increment.
        if(time >= stepSize) {
            time = 0;
            offset++;
        }
        
        time++;
        
        return (char) ('A' + offset);
    }

}
